<?php
App::uses('AppController', 'Controller');

class StaticsController extends AppController {

	/**
	* Components
	* @var array
	*/
	public $components = array(
			'RequestHandler',
			'Common',
	);

	public $uses = array('Static', 'Category', 'News');

	public function detail($static_rewrite){
		$options = array();
		$options['fields'] = array(
				'id',
				'sta_name',
				'sta_content',
				'title_seo',
				'keyword_seo',
				'description_seo',
				'Category.cat_name',
		);
		$options['conditions'] = array('md5' => md5(md5($static_rewrite) . Configure::read('Security.salt')));

		$options['joins'] = array(
				array(
					'table' => 'categories_multi',
					'alias' => 'Category',
					'type' => 'INNER',
					'conditions' => array(
						'Static.category_id = Category.id'
					)
				)
		);

		$detail_news = $this->Static->find('all', $options);
		$detail_news = reset($detail_news);

		$title_for_layout = ($detail_news['Static']['title_seo'] ? $detail_news['Static']['title_seo'] : $detail_news['Static']['sta_name']);
		$keywords_for_layout = $detail_news['Static']['keyword_seo'];
		$description_for_layout = $detail_news['Static']['description_seo'];
		$this->set(
				array(
					'detail_news' => $detail_news,
					'title_for_layout' => $title_for_layout,
					'keywords_for_layout' => $keywords_for_layout,
					'description_for_layout' => $description_for_layout,
				)
		);
	}
	public function register($register){
		echo $register;
	}

}